package com.sky.controller.admin;

import com.ejlchina.searcher.SearchResult;
import com.sky.dto.*;
import com.sky.service.OrderService;
import com.sky.vo.OrderPaymentVO;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import com.sky.web.controller.BaseController;
import com.sky.web.domain.AjaxResult;
import com.sky.web.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author tzl
 * @Date 2023-07-26 15:51:29  星期三
 * @Description: 用户订单模块接口
 */
@Api(tags = "用户订单模块接口")
@Slf4j
@RestController("adminOrderController")
@RequestMapping("/admin/order")
public class OrderController extends BaseController {


    @Autowired
    private OrderService orderService;

    /**
     * 订单搜索
     *
     * @param dto 订单信息
     * @return
     */
    @GetMapping("/conditionSearch")
    @ApiOperation("订单搜索")
    public TableDataInfo list(OrdersDTO dto) {
        SearchResult<OrderVO> result = orderService.selectlOrders(dto);
        return getDataTable(result);
    }


    /**
     * 查询订单详情
     *
     * @param id 订单id
     * @return
     */
    @GetMapping("/details/{id}")
    @ApiOperation("查询订单详情")
    public AjaxResult details(@PathVariable("id") Long id) {
        OrderVO orderVO = orderService.selectOrderVOById(id);
        return AjaxResult.success(orderVO);
    }

    /**
     * 各个状态的订单数量统计
     *
     * @return
     */
    @GetMapping("/statistics")
    @ApiOperation("各个状态的订单数量统计")
    public AjaxResult statistics() {
        OrderStatisticsVO orderStatisticsVO = orderService.statistics();
        return AjaxResult.success(orderStatisticsVO);
    }

    /**
     * 接单
     *
     * @return
     */
    @PutMapping("/confirm")
    @ApiOperation("接单")
    public AjaxResult confirm(@RequestBody OrdersDTO dto) {
        return toAjax(orderService.confirm(dto));
    }

    /**
     * 拒单
     *
     * @return
     */
    @PutMapping("/rejection")
    @ApiOperation("拒单")
    public AjaxResult rejection(@RequestBody OrdersDTO dto) {
        return toAjax(orderService.rejection(dto));
    }

    /**
     * 取消订单
     *
     * @return
     */
    @PutMapping("/cancel")
    @ApiOperation("取消订单")
    public AjaxResult cancel(@RequestBody OrdersDTO dto) {
        return toAjax(orderService.cancel(dto));
    }

    /**
     * 派送订单
     *
     * @return
     */
    @PutMapping("/delivery/{id}")
    @ApiOperation("派送订单")
    public AjaxResult delivery(@PathVariable("id") Long id) {
        return toAjax(orderService.delivery(id));
    }

    /**
     * 完成订单
     *
     * @return
     */
    @PutMapping("/complete/{id}")
    @ApiOperation("完成订单")
    public AjaxResult complete(@PathVariable("id") Long id) {
        return toAjax(orderService.complete(id));
    }
}
